package com.aaa.member.controller;

import com.aaa.common.constant.ExceptionConstant;
import com.aaa.common.constant.ReturnCode;
import com.aaa.common.util.CustomException;
import com.aaa.common.util.Result;
import com.aaa.member.entity.AccountStatement;
import com.aaa.member.service.AccountStatementService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 账户流水表(AccountStatement)表控制层
 *
 * @author makejava
 * @since 2020-11-21 14:13:34
 */
@RestController
@RequestMapping("accountStatement")
public class AccountStatementController {
    /**
     * 服务对象
     */
    @Resource
    private AccountStatementService accountStatementService;

    /**
     * 添加会员等级
     * @param accountStatement
     * @return
     */
    @PostMapping("insert")
    public Result inset(@RequestBody AccountStatement accountStatement) {
        //判断新增的角色名字为空抛出异常
        if (accountStatement.getClientId() == null) {
            throw new CustomException(ExceptionConstant.INVALID_ARGUMENT.getErrorCode(),
                    ExceptionConstant.INVALID_ARGUMENT.getErrorMessage());
        } else {
            //返回成功
            return new Result(ReturnCode.SUCCESSS.getCode(),
                    ReturnCode.SUCCESSS.getMsg(), this.accountStatementService.insert(accountStatement));
        }
    }
    /**
     * 通过年份查询操作
     * @param year
     * @return
     */
    @GetMapping("queryOpsByYear")
    public Result queryOpsByYear(String year){
        System.out.println(year);
        return this.accountStatementService.queryOpsByYear(year);
    }

    @GetMapping("selectYear")
    public List<Map> selectAllYear(){

        return accountStatementService.selectAllYear();
        /*List<Integer> list1 = new ArrayList();
        List<Map> list = operLogService.selectAllYear();
        for(Map map : list){
            Integer yy = (Integer)map.get("yy");
            list1.add(yy);
        }
        return list1;*/
    }
}